//获取今天日期时间戳YYYY-MM-DD
function getNowDate(){
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate =date.getDate() ;
  if (month >= 1 && month <= 9) {
	month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
	strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  var timeStamp = parseInt(date.getTime(currentdate)/1000)
  // console.log(currentdate)
  // console.log(timeStamp)
  return timeStamp
};
// 获取13位时间戳
function getNowDate2(){
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate =date.getDate() ;
  if (month >= 1 && month <= 9) {
	month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
	strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  var timeStamp = parseInt(date.getTime(currentdate))
  // console.log(currentdate)
  // console.log(timeStamp)
  return timeStamp
};
// 今天的日期
//getYMD
//getFullTime
//getYMDHM
//getYMDHMS
function getNowDateTime(){
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate =date.getDate() ;
  if (month >= 1 && month <= 9) {
	month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
	strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate
};
function getMD(){
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate =date.getDate() ;
  if (month >= 1 && month <= 9) {
	month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
	strDate = "0" + strDate;
  }
  var currentdate =  month + seperator1 + strDate;
  return currentdate
};
// 7天前的日期时间戳
function get7Date(){
  // var date = new Date();
  // var seperator1 = "-";
  // var year = date.getFullYear();
  // var month = date.getMonth() + 1;
  // var strDate =date.getDate() -7;
  // if (month >= 1 && month <= 9) {
  // 	month = "0" + month;
  // }
  // if (strDate >= 0 && strDate <= 9) {
  // 	strDate = "0" + strDate;
  // }
  // var currentdate2 = year + seperator1 + month + seperator1 + strDate;
  // var date2=new Date(currentdate2)
  // var temptime=date2.getTime()-8*60*60*1000
  // var timeStamp = parseInt(temptime/1000) 
  // console.log(currentdate2)
  // console.log(timeStamp)
  // return timeStamp 
  var date = new Date();
  var date7=new Date(date.getTime() - 168*60*60*1000)
  var timeStamp = parseInt(date7/1000) 
  // console.log(timeStamp)
  return timeStamp
};
// 7天前的日期
function get7DateTime(){
  var date1 = new Date();
  var date2=new Date(date1)
  date2.setDate(date1.getDate()-7)
  var seperator1 = "-";
  var year = date2.getFullYear();
  var month = date2.getMonth() + 1;
  var strDate =date2.getDate() ;
  if (month >= 1 && month <= 9) {
  	month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
  	strDate = "0" + strDate;
  }
  var currentdate2 = year + seperator1 + month + seperator1 + strDate;
  // console.log(currentdate2) 
 
  return currentdate2
};
function getNowDateTimeFolder(){
 //  var date = new Date();
 //  var seperator1 = "-";
 //  var year = date.getFullYear();
 //  var month = date.getMonth() + 1;
 //  var strDate =date.getDate() ;
 //  if (month >= 1 && month <= 9) {
	// month = "0" + month;
 //  }
 //  if (strDate >= 0 && strDate <= 9) {
	// strDate = "0" + strDate;
 //  }
 //  var currentdateFolder = year  + month  + strDate;
 //  return currentdateFolder
 const date = new Date();
 const year = date.getFullYear();
 const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始，需加1并补零
 const day = date.getDate().toString().padStart(2, '0'); // 补零
 return `${year}${month}${day}`;
};
// 时间戳 转时间YYYY-MM-DD HH:MM格式
function turnTime(x) {
	var date = new Date(x)
	var Y = date.getFullYear() + '-'
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
	var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
	var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
	var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) 
	return Y + M + D + h + m
};
// 实践戳转年月日小时分钟秒
function shijianc(time) {
            var date = new Date(time)
            var Y = date.getFullYear() + '-'
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
            var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '
            var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
            var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
            var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())
            return Y + M + D + h + m + s

        };

// 获取时间，年月日小时分秒
function getNow(){
	var date = new Date();
	var seperator1 = "-";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate =date.getDate() ;
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var hh = date.getHours()
	var mm = date.getMinutes()
	var ss = date.getSeconds()
	if (hh >= 0 && hh <= 9) {
		hh = "0" + hh;
	}
	if (mm >= 0 && mm <= 9) {
		mm = "0" + mm;
	}
	if (ss >= 0 && ss <= 9) {
		ss = "0" + ss;
	}
	var currentdate = year + seperator1 + month + seperator1 + strDate+' '+hh+':'+mm+':'+ss;
	return currentdate
};
// 获取YYYY-MM-DD HH:MM
function getNowTime(){
	var date = new Date();
	var seperator1 = "-";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate =date.getDate() ;
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var hh = date.getHours()
	var mm = date.getMinutes()
	if (hh >= 0 && hh <= 9) {
		hh = "0" + hh;
	}
	if (mm >= 0 && mm <= 9) {
		mm = "0" + mm;
	}
	
	var currentdate = year + seperator1 + month + seperator1 + strDate+' '+hh+':'+mm;
	return currentdate
}
function parseDateTime(dateTimeStr) {
    // 将中文日期格式转换为标准的 Date 对象
    const date = new Date(dateTimeStr.replace(/年|月/g, '-').replace('日', ''));

    // 检查日期是否有效
    if (isNaN(date.getTime())) {
        throw new Error('Invalid date format');
    }

    // 获取时间部分（hh:mm）
    const hours = String(date.getHours()).padStart(2, '0'); // 小时
    const minutes = String(date.getMinutes()).padStart(2, '0'); // 分钟
    const time = `${hours}:${minutes}`; // 组合成 hh:mm 格式

    // 获取日期部分（yyyy-mm-dd）
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始，需要 +1
    const day = String(date.getDate()).padStart(2, '0');
    const formattedDate = `${year}-${month}-${day}`;

    // 获取星期几
    const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    const weekDay = weekdays[date.getDay()]; // getDay() 返回 0（星期日）到 6（星期六）

    // 返回解析结果
    return {
        time: time,         // 时间（hh:mm）
        date: formattedDate, // 日期（yyyy-mm-dd）
        weekDay: weekDay    // 星期几
    };
}
module.exports= {
	getNowDate:getNowDate,
	get7Date:get7Date,
	turnTime:turnTime,
	get7DateTime:get7DateTime,
	getNowDateTime:getNowDateTime,
	getNow:getNow,
	shijianc:shijianc,
	getNowDate2:getNowDate2,
	getNowTime:getNowTime,
	getMD:getMD,
	getNowDateTimeFolder:getNowDateTimeFolder,
	parseDateTime:parseDateTime
}